import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

public class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode() {}
    TreeNode(int val) {this.val = val;}
    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }

    public String toString() {
        List<String> res = new ArrayList<>();
        Queue<TreeNode> queue = new LinkedList<>();
        queue.add(this);
        while(!queue.isEmpty()) {
            TreeNode item = queue.poll();
            if (item.val == -1) {
                res.add("null");
                continue;
            }
            res.add("" + item.val);
            if (item.left == null) { queue.add(new TreeNode(-1));}
            if (item.right == null) { queue.add(new TreeNode(-1));}
            if (item.left != null) { queue.add(item.left); }
            if (item.right != null) { queue.add(item.right); }
        }
        return res.toString();
    }
}
